<?php
/**
 *Administra los departamentos del sitio web
 *@author Luis Gabriel Rodriguez <luisgabriel84@gmail.com>
 */

/**
 *Administra los departamentos del sitio web
 */
class StatesController extends AppController {

	var $name = 'States';
        /**
        * @var array
        * @access public
        */
	var $helpers = array('Html', 'Form');

         /**
         * Listado de departamento para el administrador
         */
	function admin_index() {
	    $this->layout='admin';
		$this->State->recursive = 0;
		$this->set('states', $this->paginate());
	}
         /**
         *
         * Agrega un departamento
         */

	function admin_add() {
	    $this->layout='admin';
		if (!empty($this->data)) {
			$this->State->create();
			if ($this->State->save($this->data)) {
				$this->Session->setFlash(__('The State has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The State could not be saved. Please, try again.', true));
			}
		}
	}
         /**
         *
         * Modifica un departamento
         *@param integer $id Identificador del departamento
         */
	function admin_edit($id = null) {
	    $this->layout='admin';
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid State', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->State->save($this->data)) {
				$this->Session->setFlash(__('The State has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The State could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->State->read(null, $id);
		}
	}
        /**
         * Elimina un departamento
         * @param integer $id Identificador del departamento
         */
	function admin_delete($id = null) {
	    $this->layout='admin';
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for State', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->State->del($id)) {
			$this->Session->setFlash(__('State deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}
}
?>